import React, { Component } from 'react'
import style from './searchAddress.module.scss';
import { connect } from 'react-redux'
import { changeLocationSelectedAction } from '@/store/modules/Shipping/shippingActiveCreate.js'
import { regionChangeCurrentLocationAction } from '@/store/modules/Region/regionActiveCreate.js'


class SearchAddress extends Component {
    render() {
        return (
            this.props.searchAddressList.map((item) => {
                return (<div key={item.id} className={style.searchAddressItem} onClick={() => { this.twext(item) }}>
                    <p className={style.addressItemName}>{item.name} <span className={style.itemDistance}>{item.distance}</span></p>
                    <p className={style.itemAddress}>{item.address}</p>
                </div>)
            })
        )
    }
    twext = (obj) => {
        this.props.delsearchAddressList()
        this.props.changeLocationSelected(obj)
        this.props.changeCurrentLocation(obj)
    }
}

const stateToProps = (state) => {
    return {
    }
}

const dispatchToProps = (dispatch) => {
    return {
        changeLocationSelected: (value) => {//修改所在位置
            let action = { value }
            dispatch(changeLocationSelectedAction(action))
        },
        changeCurrentLocation: (value) => {//修改所在地区位置
            let action = { value }
            dispatch(regionChangeCurrentLocationAction(action))
        }
    }
}


export default connect(stateToProps, dispatchToProps)(SearchAddress)